package com.cysyz.mylib.dao;


import com.cysyz.mylib.dao.engine.PersistenceEngine;
import com.cysyz.mylib.dao.engine.Query;
import com.cysyz.mylib.dao.type.Type;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public interface BaseDao {
	public abstract void save(Object entity);

	public abstract <T> void remove(Class<T> clazz, Serializable entityID);

	@SuppressWarnings("rawtypes")
	public abstract void removeByCollection(List list);
	
	public int execute(String ql, List<Object> params);

	public int executeSql(String sql, List<Object> params);

    /**
     *  执行sql取得结果列表
     * @param sql sql语句
     * @param params 参数集合
     * @param clazz 存储返回值的对象
     * @param scalars   别名的类型说明
     * @return  对象的集合
     */
    public <T> List<T> list (String sql, List<Object> params, Class<T> clazz, Map<String, Type> scalars);

    public <T> PagingResult<T> listPaging (String sql, List<Object> params, Class<T> clazz, int page, int maxresult);
	
	public <T> List<T> list (String sql, List<Object> params, Class<T> clazz);
	
	public abstract void update(Object entity);

	public abstract <T> T get(Class<T> clazz, Serializable entityID);
	
	public abstract  <T> T load(Class<T> clazz, Serializable entityID);

	public abstract <T> long getCount(Class<T> clazz, Conds conds, Query queryForData);

	public abstract <T> long getCount(Class<T> clazz);
	
	public <T> long getCount(Class<T> clazz, Conds conds);
	
	public abstract <T> List<T> list(Class<T> clazz, boolean isDistinct, String[] fieldNames, Conds conds);
	
	public abstract <T> List<T> list(Class<T> clazz, boolean isDistinct, String[] fieldNames);

	public abstract <T> List<T> list(Class<T> clazz, String[] fieldNames,
			Conds conds);

	public abstract <T> List<T> list(Class<T> clazz, Conds conds);

	public abstract <T> List<T> list(Class<T> clazz);

	public abstract <T> List<T> listCacheAble(Class<T> clazz, boolean isDistinct, String[] fieldNames, Conds conds);
	
	public abstract <T> List<T> listCacheAble(Class<T> clazz, String[] fieldNames,
			Conds conds);
	
	public abstract <T> List<T> listCacheAble(Class<T> clazz, Conds conds);
	
	public abstract <T> List<T> listCacheAble(Class<T> clazz);

	public abstract <T> PagingResult<T> listPaging(Class<T> clazz, int page,
			int maxresult);

	public abstract <T> PagingResult<T> listPaging(Class<T> clazz, Conds conds,
			int page, int maxresult);
	
	public abstract <T> PagingResult<T> listPaging(Class<T> clazz, String queryPrefix, String queryPostfix, int page, int maxresult);
	
	public abstract <T> PagingResult<T> listPaging(Class<T> clazz, Conds conds, String queryPrefix, String queryPostfix, int page, int maxresult);
	
	public PersistenceEngine getPersistenceEngine();
	
	public void setPersistenceEngine(PersistenceEngine persistenceEngine);

	public <T> List<T> list(Class<T> clazz, String queryPrefix, String queryPostfix);

	public <T> List<T> list(Class<T> clazz, String queryPrefix);

    public <T> PagingResult<T> listPaging (String sql, List<Object> params, Class<T> clazz, Map<String, Type> scalars, int page, int maxresult);

    Object getSingleResult(String ql, Map<String, Object> paramPlaceAndValues);

	public <T> long getCount(Class<T> clazz, Conds conds, String queryPostfix);
}